package org.jeik.beackBeans.forms;

import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;

import org.jeik.beackBeans.BeansBase;
import org.jeik.common.Constants;
import org.jeik.controllers.MsgsController;
import org.jeik.controllers.NavigationController;
import org.jeik.controllers.NavigationRule;
import org.jeik.controllers.SystemMsgs;
import org.jeik.utils.EmailUtils;
import org.jeik.utils.EmailUtils.EmailType;

public class ComplaintsFormBean extends BeansBase {

	private static final long serialVersionUID = 1L;

	private String name;
	private String email;
	private String phone;
	private String type;
	private String division;
	private String message;
	
	@PostConstruct
	public void init() {
		type = "إستفسار";
	}

	public void submitForm() {

		String emailBody = "<html dir=\"rtl\"><head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\"></head><body>";
		emailBody += "<table style='font-size:13px;font-family:Tahoma;'>";
		emailBody += "<tr><td style='width:150px;font-weight:bold;vertical-align:top;'>الإسم</td><td style='width:500px;'>"
				+ getName() + "</td></tr>";
		emailBody += "<tr><td style='font-weight:bold;vertical-align:top;'>البريد الإلكتروني</td><td>"
				+ getEmail() + "</td></tr>";
		emailBody += "<tr><td style='width:150px;font-weight:bold;vertical-align:top;'>القسم</td><td style='width:500px;'>"
				+ getDivision() + "</td></tr>";
		emailBody += "<tr><td style='font-weight:bold;vertical-align:top;'>الهاتف</td><td>"
				+ getPhone() + "</td></tr>";
		emailBody += "<tr><td style='font-weight:bold;vertical-align:top;'>الموضوع</td><td>"
				+ getType() + "</td></tr>";
		emailBody += "<tr><td style='font-weight:bold;vertical-align:top;'>الرسالة</td><td>"
				+ getMessage() + "</td></tr>";
		emailBody += "</table></body></html>";

		

		EmailUtils.sendEmail("info@jordanembassykw.com",
				"Feedback at Jordan Embassy Website",
				Constants.Configs.ADMIN_EMAIL, getType(), emailBody,
				EmailType.HTML);

		MsgsController.addFacesGlobalMessage(FacesMessage.SEVERITY_INFO, SystemMsgs.MESSAGE_SENT_SUCCESSFULLY);

		NavigationController.navigate(NavigationRule.RESULT);

	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getDivision() {
		return division;
	}

	public void setDivision(String division) {
		this.division = division;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

}
